package com.scsj.supermarket.presenter;

import android.util.Log;

import com.scsj.supermarket.base.IndexBase;
import com.scsj.supermarket.bean.IndexBean;
import com.scsj.supermarket.bean.IndexMarketBean;
import com.scsj.supermarket.model.IndexModel;

import java.util.Map;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 首页除去店铺
 */

public class IndexPresenter extends BasePresenter implements IndexBase.IPresenter {

    private IndexBase.IModel mModel;
    private IndexBase.IView mView;

    public IndexPresenter(IndexBase.IView view) {
        mView = view;
        mModel = new IndexModel();
    }

    @Override
    public void deliverAllList(RequestBody requestBody) {

        addSubscription(mModel.getData(requestBody, new ResponseCallback<IndexBean>() {
            @Override
            public void onSuccess(IndexBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("首页数据拿到了，sb");
                    mView.setAllData(result);
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }
            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverMarketList(RequestBody requestBody) {

        addSubscription(mModel.getIndexMarketData(requestBody, new ResponseCallback<IndexMarketBean>() {
            @Override
            public void onSuccess(IndexMarketBean result) {

                if (result.getStatusCode() == 200) {
                    mView.showSuccessMsg("首页店铺数据拿到了，sb");
                    mView.setIndexMarketData(result);
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }
            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }
}
